var t = require("../../../@babel/runtime/helpers/defineProperty"), e = require("../../../utils/DPagination").default, a = require("../../../utils/util").formatTimeTwo, s = require("../common").getProjectNameLang, i = getApp(), n = i.getNetAddresss("plugin.store-projects.frontend.project-service.get-list"), o = i.getNetAddresss("plugin.store-projects.frontend.project-service.get-worker-summary"), r = i.getNetAddresss("plugin.store-projects.frontend.project-service.get-store-summary"), c = new e("projects"), d = 0;

Page({
    data: {
        pageType: "used",
        displayRecordTimeRangeSelect: !1,
        storeName: "",
        staffName: "",
        projectName: "",
        staffKeyword: "",
        timeRange: {
            start: a(Date.now() / 1e3 - 604800, "Y-M-D"),
            end: a(Date.now() / 1e3, "Y-M-D")
        },
        projects: {},
        projectCount: 0,
        statistics: null,
        projectNameLang: s(),
        select_use_type_arr: [ "全部", "核销使用", "转赠-转出" ],
        select_use_type_index: 0
    },
    onLoad: function(t) {
        var e = t.type;
        switch (e) {
          case "store":
            wx.setNavigationBarTitle({
                title: "商户记录"
            }), d = 2, this.getStoreStatistics();
            break;

          case "used":
            wx.setNavigationBarTitle({
                title: "使用记录"
            }), d = 0;
            break;

          case "staff":
            wx.setNavigationBarTitle({
                title: "核销员记录"
            }), d = 1, this.getStaffStatistics();
        }
        var a = {
            pageType: e
        };
        t.project_name && (a.projectName = t.project_name), this.setData(a), c.bind(this), 
        this.getProjects();
    },
    onReady: function() {},
    onShow: function() {},
    onHide: function() {},
    onUnload: function() {
        c.clean();
    },
    onPullDownRefresh: function() {
        c.clean(), this.getProjects();
    },
    onReachBottom: function() {
        this.getProjects();
    },
    onShareAppMessage: function() {},
    displayCaleandar: function() {
        this.setData({
            displayRecordTimeRangeSelect: !this.data.displayRecordTimeRangeSelect
        });
    },
    calendarConfirmSelect: function(t) {
        var e = t.detail;
        this.setData({
            displayRecordTimeRangeSelect: !1,
            timeRange: {
                start: a(new Date(e[0]).getTime() / 1e3, "Y-M-D"),
                end: a(new Date(e[1]).getTime() / 1e3, "Y-M-D")
            }
        });
    },
    inputElChanged: function(e) {
        var a = e.detail.value, s = e.target.dataset;
        this.setData(t({}, s.name, a));
    },
    searchProjects: function(t) {
        c.clean(), this.getProjects();
    },
    getProjects: function() {
        var t = this;
        c.finished || c.loading || (c.loading = !0, wx.showLoading(), i._getNetWork({
            url: n,
            data: {
                page: c.loadPage,
                owner_type: d,
                project_name: this.data.projectName,
                store_name: this.data.storeName,
                verify_kwd: this.data.staffName,
                start_date: this.data.timeRange.start,
                end_date: this.data.timeRange.end,
                use_type: this.data.select_use_type_index
            },
            success: function(e) {
                var a = e.data, s = a.data, i = a.result, n = a.msg;
                0 != i ? (wx.hideLoading(), c.loading = !1, wx.stopPullDownRefresh(), (s.last_page == s.current_page || s.data.length < s.per_page) && (c.finished = !0), 
                c.push(s.data), t.setData({
                    projectCount: c.length
                })) : wx.showToast({
                    title: n,
                    icon: "none"
                });
            }
        }));
    },
    getStatistics: function(t) {
        var e = this;
        i._getNetWork({
            url: t,
            success: function(t) {
                var a = t.data.data, s = t.result, i = t.msg;
                0 !== s ? e.setData({
                    statistics: a
                }) : wx.showToast({
                    title: i,
                    icon: "none"
                });
            }
        });
    },
    getStaffStatistics: function() {
        this.getStatistics(o);
    },
    getStoreStatistics: function() {
        this.getStatistics(r);
    },
    dateRangeChanged: function(e) {
        var a = e.detail.value, s = e.target.dataset.type;
        this.setData(t({}, "timeRange.".concat(s), a));
    },
    cleanTime: function() {
        this.data.timeRange.start && this.data.timeRange.end && this.setData({
            timeRange: {
                start: "",
                end: ""
            }
        });
    },
    onSelectType: function() {
        var t = this;
        wx.showActionSheet({
            itemList: this.data.select_use_type_arr,
            success: function(e) {
                t.setData({
                    select_use_type_index: e.tapIndex
                }), console.log(e.tapIndex);
            },
            fail: function(t) {
                console.log(t.errMsg);
            }
        });
    }
});